Size Property Example

This example demonstrates the Size property by enumerating the names and sizes of the Field objects in the Employees table.

Sub SizeX()

    Dim dbsNorthwind As Database
    Dim tdfEmployees As TableDef
    Dim fldNew As Field
    Dim fldLoop As Field

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set tdfEmployees = dbsNorthwind.TableDefs!Employees

    With tdfEmployees

        ' Create and append a new Field object to the 
        ' Employees table.
        Set fldNew = .CreateField("FaxPhone")
        fldNew.Type = dbText
        fldNew.Size = 20
        .Fields.Append fldNew

        Debug.Print "TableDef: " & .Name
        Debug.Print "  Field.Name - Field.Type - Field.Size"

        ' Enumerate Fields collection; print field names, 
        ' types, and sizes.
        For Each fldLoop In .Fields
            Debug.Print "    " & fldLoop.Name & " - " & _
                fldLoop.Type & " - " & fldLoop.Size
        Next fldLoop

        ' Delete new field because this is a demonstration.
        .Fields.Delete fldNew.Name

    End With

    dbsNorthwind.Close

End Sub